
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

def grid_test():
    # 1. 配置浏览器选项
    chrome_options = Options()
    chrome_options.platform_name = "WINDOWS"  # 指定操作系统
    # chrome_options.browser_version = "120"  # 可选：指定浏览器版本
    
    # 2. 连接到 Grid Hub
    hub_url = "http://192.168.1.69:4444/wd/hub"
    driver = webdriver.Remote(
        command_executor=hub_url,
        options=chrome_options
    )
    
@pytest.fixture(scope='session')
def browser():
    #在异地node上执行 1. 配置浏览器选项
    chrome_options = Options()
    chrome_options.platform_name = "WINDOWS"  # 指定操作系统
    # chrome_options.browser_version = "120"  # 可选：指定浏览器版本
    # hub_url = "http://192.168.1.69:4444/wd/hub"
    # wd = webdriver.Remote(
    #     command_executor=hub_url,
    #     options=chrome_options
    # )
    # 在本地浏览器上执行
    service = Service(executable_path=r'D:\pulg\webdriver\chromedriver-win64\chromedriver.exe')   
    wd = webdriver.Chrome(service=service)
    wd.maximize_window()
    wd.implicitly_wait(2)
    yield wd
    wd.quit()